<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>你好，<span id='name'></span></p>
    </div>
    <script>
        var obj = {};
        // 定义数据劫持
        Object.defineProperty(obj, "name", {
            get() {
                console.log('获取name')
                return document.querySelector('#name').innerHTML;
            },
            set(nick) {
                console.log('设置name')
                document.querySelector('#name').innerHTML = nick;
            }
        });
    
        obj.name = "Jerry";
        console.log(obj.name)
    </script>
</body>
</html>